package cn.tvplaza.shakeclub.shakermb;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.tvplaza.shakeclub.R;
import cn.tvplaza.shakeclub.community.activity.SearchFriendActivity;
import cn.tvplaza.shakeclub.shakermb.adapter.UserMoneyAdapter;
import cn.tvplaza.shakeclub.shakermb.adapter.UserMoneyBean;

/**
 * @Created by taylor on 7/10/17.
 * @class description 摇红包首页
 */

public class HomeShakeFragment extends Fragment {

    @Bind(R.id.iv_shake_switch_btn)
    ImageView switchBtn;
    @Bind(R.id.rcv_user_lucky_money_list)
    RecyclerView mRecyclerView;

    private boolean mBoolPowerOn = false;
    private UserMoneyAdapter mAdapter;
    private List<UserMoneyBean> mDatas;

    //    AlertController.RecycleListView

    public static HomeShakeFragment newInstance() {
        return new HomeShakeFragment();
    }

    public HomeShakeFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View root = inflater.inflate(R.layout.fragment_home_shake, null);
        ButterKnife.bind(this, root);
        init();
        return root;

    }

    private void init() {

        mDatas = new ArrayList<>();
        for (int i = 0; i < 40; i++) {
            UserMoneyBean bean = new UserMoneyBean();
            if (i % 3 == 0) {
                bean.setMsg("12.6");
                bean.setUserName("孙红红");
                bean.setUserHint("太幸运了！！！哈哈");
            } else if (i % 2 == 0) {
                bean.setUserName("小泓雨");
                bean.setUserHint("摇到一个提现锦囊");
            } else {
                bean.setUserName("Candis");
                bean.setUserHint("摇到一个提现锦囊");
            }
            mDatas.add(bean);
        }
        mAdapter = new UserMoneyAdapter(getActivity(), mDatas);
        //设置Adapter
        mRecyclerView.setAdapter(mAdapter);
        //设置布局管理器
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        //设置item动画
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    }

    @OnClick({R.id.iv_shake_switch_btn, R.id.iv_shake_main_btn, R.id.ll_search_input})
    public void onClickBind(View v) {
        switch (v.getId()) {
            case R.id.iv_shake_main_btn:

                break;
            case R.id.iv_shake_switch_btn:
                if (mBoolPowerOn) {
                    mBoolPowerOn = false;
                    switchBtn.setImageResource(R.mipmap.ic_launcher_gray);
                } else {
                    mBoolPowerOn = true;
                    switchBtn.setImageResource(R.mipmap.ic_launcher);
                }
                break;
            case R.id.ll_search_input:
                Intent i = new Intent(getActivity(), SearchFriendActivity.class);
                i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                getActivity().overridePendingTransition(0, 0);
                startActivity(i);
                break;
        }
    }
}
